package cn.edu.zafu.bigdata.lwg;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class GenericMaxFinder {

    public static <T> T findMax(List<T> list, Comparator<T> comparator) {
        if (list == null || list.isEmpty()) {
            throw new IllegalArgumentException("List must not be null or empty");
        }
        return Collections.max(list, comparator);
    }

    public static <T extends Comparable<T>> T findMax(List<T> list) {
        return findMax(list, Comparator.naturalOrder());
    }

    public static void main(String[] args) {
        List<Integer> integerList = List.of(1, 3, 5, 7, 9);
        List<String> stringList = List.of("apple", "banana", "cherry", "date");

        Integer maxInteger = findMax(integerList);
        String maxString = findMax(stringList);

        System.out.println("Max integer: " + maxInteger);
        System.out.println("Max string: " + maxString);
    }
}